package com.zp.business.controller.exam;

import com.zp.business.entity.exam.bo.ExamApplyBo;
import com.zp.business.entity.exam.vo.ExamApplyVo;
import com.zp.business.service.exam.IExamApplyService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 检查申请主控制器
 * 前端访问路由地址为:/business/examApply
 *
 * @author zhang peng
 * @ date 2024-01-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/examApply")
public class ExamApplyController extends BaseController {

    private final IExamApplyService iExamApplyService;

    /**
     * 查询检查申请主列表 (分页)
     */
//    @SaCheckPermission("business:examApply:list")
    @GetMapping("/selectPage")
    public TableDataInfo<ExamApplyVo> selectPage (ExamApplyBo bo, PageQuery pageQuery) {
        return iExamApplyService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询检查申请主列表 (不分页)
     */
//    @SaCheckPermission("business:examApply:list")
    @GetMapping("/list")
    public R<List<ExamApplyVo>> list (ExamApplyBo bo) {
        List<ExamApplyVo> list = iExamApplyService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出检查申请主列表
     */
//    @SaCheckPermission("business:examApply:export")
    @Log(title = "检查申请主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (ExamApplyBo bo, HttpServletResponse response) {
        List<ExamApplyVo> list = iExamApplyService.queryList(bo);
        ExcelUtil.exportExcel(list, "检查申请主", ExamApplyVo.class, response);
    }

    /**
     * 获取检查申请主详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("business:examApply:list")
    @GetMapping("/{id}")
    public R<ExamApplyVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iExamApplyService.queryById(id));
    }

    /**
     * 新增检查申请主
     */
//    @SaCheckPermission("business:examApply:add")
    @Log(title = "检查申请主", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody ExamApplyBo bo) {
        return toAjax(iExamApplyService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 保存检查申请明显
     */
    @Log(title = "保存检查申请明显", businessType = BusinessType.INSERT)
    @PostMapping("saveExamApplyAndItem")
    public R<Void> saveExamApplyAndItem (@Validated(AddGroup.class) @RequestBody ExamApplyBo bo) {
        return toAjax(iExamApplyService.saveExamApplyAndItem(bo) ? 1 : 0);
    }

    /**
     * 修改检查收费状态、确认状态
     */
    @Log(title = "修改检查收费状态、确认状态", businessType = BusinessType.UPDATE)
    @PostMapping("examConfirmOk")
    public R<Void> examConfirmOk(@RequestBody ExamApplyBo bo) {
        return toAjax(iExamApplyService.examConfirmOk(bo) ? 1 : 0);
    }

    /**
     * 修改检查申请主
     */
//    @SaCheckPermission("business:examApply:edit")
    @Log(title = "检查申请主", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody ExamApplyBo bo) {
        return toAjax(iExamApplyService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除检查申请主
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("business:examApply:remove")
    @Log(title = "检查申请主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        int i = iExamApplyService.deleteWithValidByIds(Arrays.asList(ids), true);
        return R.ok(i);
    }
}
